<?php
/*
Mooha Server - SyncML Server written in PHP (http://mooha.net)
Copyright (C) 2009	Artem Bandur <artico.bandurini@gmail.com>
					Madcap BV (http://www.madcap.nl)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

// set path to error.log file ()
ini_set('error_log', dirname(__FILE__) . '/error.log');

// set timezone to get rid of warnings in PHP >= 5.3.0
if (!ini_get('date.timezone')) {
  ini_set('date.timezone', @date_default_timezone_get());
}
// set error reporting level
error_reporting(E_ALL); // set '0' to disable error reporting, 'E_ALL' to view all errors, 'E_ALL & ~E_NOTICE' to view all except notices

// do not show errors in pages (must be FALSE in production)
ini_set('display_errors', FALSE);

// disable HTML in screen error messages
ini_set('html_errors', FALSE);

// session configuration
ini_set('session.gc_maxlifetime', 900);
ini_set('session.cache_expire', 600);
ini_set('session.use_cookies', 0);
@ini_set('session.use_trans_sid', 0);

// handle exceptions like errors
function moohaExceptionHandler($e) {
  $logLines = array();
  while ($e) {
    $eClass = get_class($e);
    $logLines[]= $eClass . ': ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine();
    if (method_exists($e, 'getPrevious') || $eClass == 'SyncmlException') {
      $e = $e->getPrevious();
    }
    else {
      break;
    }
  }
  $log = implode("\n...", $logLines) . "\n";
  trigger_error($log, E_USER_ERROR);
}
set_exception_handler('moohaExceptionHandler');

// handle errors in usual way (logfile) instead of set earlier by drupal etc.
restore_error_handler();

// constants
define('WBXML_VERSION', '1.0');
define('WBXML_USE_EXTERNAL', FALSE);  // allow using command-line tools for decoding/encoding of wbxml